package com.kaka.bus.engine.borrow.phone;

import android.app.Activity;

import com.kaka.bus.bean.HttpWrapper;
import com.kaka.bus.di.DataManager;
import com.kaka.bus.engine.RouterUtil;
import com.kaka.bus.manager.Result;
import com.kaka.bus.manager.T;
import com.kaka.bus.mvp.RxPresenter;

import java.util.Map;

import javax.inject.Inject;

/**
 * Created by zhangqi on 2016/10/18.
 * e-mail : ${email}
 * desc :
 */

public class PhoneYzmPresenter extends RxPresenter<PhoneYzmContract.View> implements PhoneYzmContract.Presenter{

    @Inject
    public PhoneYzmPresenter(DataManager dataManager) {
        super(dataManager);
    }

    @Override
    public void commitYzm(Map<String, String> map, String tips) {
        mView.showDialog(tips);

        addSubscribe(mDataManager
                .getApi()
                .commitPhonePwdRc(map)
                .compose(T.D())
                .subscribeWith(new Result<HttpWrapper<String>>() {
                    @Override
                    protected void onSuccess(HttpWrapper<String> data) {
                        mView.getResult(data);
                    }

                    @Override
                    protected void onFinish() {
                        mView.dissDialog();
                    }
                }));
    }

    @Override
    public void router(Activity activity) {
        mView.showDialog("查询节点中...");
        RouterUtil.router(activity, mDataManager.getApi(),mCompositeDisposable, () -> {
            mView.dissDialog();
        });
    }
}
